package edu.berkeley.cs160.prog1;


import java.util.ArrayList;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
//import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
//import android.widget.Button;
//import android.widget.EditText;
//import android.widget.PopupWindow;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

public class RestaurantActivity extends Activity implements OnClickListener, OnEditorActionListener {
	
	private ArrayList<String> actionList = new ArrayList<String>();
	private ArrayList<String> emotionList = new ArrayList<String>();
	
	//TODO: popup should cut from here
	private static final int emotion = 0;
	private static final int action = 1;
	private static final int enter_response = 2;
	public int touchCount = 0; //use to count the number of touches on msg box. 
							  //Start popups for 0, start typing msg when touchCount is 1
							  //set back to 0 when press "send" button in the textbox
	
	final CharSequence[] emotions = {"Happy", "Angry", "Sad", "calm"};
	final CharSequence[] actions = {"Do Nothing", "Smile", "Frown", "Wave"};
	
    @Override
    protected Dialog onCreateDialog(int id) {
    	AlertDialog popup;
        switch (id) {
        case emotion:
            AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
            builder1.setTitle("Pick an emotion");
            builder1.setItems(emotions, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    //Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
                }
            });
            popup = builder1.create();
            
            break;
            
        case action:
            AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
            builder2.setTitle("Pick an action");
            builder2.setItems(actions, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    //Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
                }
            });
            popup = builder2.create();
            
            break;
            
        case enter_response:
        	AlertDialog.Builder builder3 = new AlertDialog.Builder(this);
        	builder3.setMessage("Now enter your response in the text box")
            .setCancelable(false)
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                     dialog.cancel();
                }
            });
            
        popup = builder3.create();
        break;
        
        default:
        	popup = null; //no match
        }
        return popup;
    } //end of onCreateDialog
	
	//TODO: popup should cut end here

	
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.restaurant_view);
        showDialog(enter_response);
        showDialog(action); //This popup window will show up after emotion window, weird!
        showDialog(emotion);
        
        //PopupWindow pw = new PopupWindow(findViewById(R.layout.aeselect_view),384,384,true);
        /*Intent myIntent = new Intent(this, Select.class);		//create a new activity!!@@@@@
        Bundle action = new Bundle();
        action.putStringArrayList("actions", actionList);
        action.putStringArrayList("emotions", emotionList);
        myIntent.putExtras(action);
        this.startActivity(myIntent);		//start a different activity!!!!!!@@@@@ */
        
        //TODO: This is part of popup, starts from here
        /*
        if (touchCount == 0) {
        	Button textBox = (Button) findViewById(R.id.textbox);	//TODO: don't forget to add the id in xml
        	textBox.setOnClickListener(new OnClickListener() {
        		public void onClick(View v) {
        			showDialog(emotion);
        		}
        	});
        
        }
        //TODO: popup ends here
         * 
         */
    }
    

    
    public void onClick (View v) {
    	
    	this.finish();
    }


	public boolean onEditorAction(TextView splitEditor, int actionId, KeyEvent event) {
		return true;

	}



	public ArrayList<String> getActionList() {
		return actionList;
	}



	public void setActionList(ArrayList<String> actionList) {
		actionList.add("Do Nothing");
		actionList.add("Smile");
		actionList.add("Frown");
		actionList.add("Wave");
		this.actionList = actionList;
	}



	public ArrayList<String> getEmotionList() {
		return emotionList;
	}



	public void setEmotionList(ArrayList<String> emotionList) {
		emotionList.add("Happy");
		emotionList.add("Angry");
		emotionList.add("Sad");
		emotionList.add("Calm");
		this.emotionList = emotionList;
	}
    
}